package com.itheima.admin.controller;

import com.itheima.PageVo;
import com.itheima.Result;
import com.itheima.admin.dto.ModuleAddDto;
import com.itheima.admin.dto.ModuleEditDto;
import com.itheima.admin.dto.ModuleListDto;
import com.itheima.admin.dto.PageDto;
import com.itheima.admin.pojo.Module;
import com.itheima.admin.service.IModuleService;
import com.itheima.admin.vo.DeptVo;
import com.itheima.admin.vo.ModuleListVo;
import com.itheima.admin.vo.ModuleVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/module")
@CrossOrigin
public class ModuleController {
    @Autowired
    private IModuleService moduleService;

    @PostMapping("/list")
    @ApiOperation("模块数据条件分页查询")
    public PageVo<ModuleVo> queryByPage(@RequestBody PageDto pageDto){
        return moduleService.queryByPage(pageDto);
    }
    @PostMapping("/add")
    @ApiOperation("添加模块")
    public Result addModule(@RequestBody ModuleAddDto moduleAddDto){
            boolean result = moduleService.addModule(moduleAddDto);
            return new Result(result,result?"添加模块成功":"添加模块失败",null);
    }
    @DeleteMapping("/{id}")
    @ApiOperation("删除模块")
    public Result deleteModule(@PathVariable("id") String id){
        boolean result = moduleService.deleteModule(id);
        return new Result(result,result?"删除模块成功":"删除模块失败",null);
    }
    @GetMapping("/{id}")
    @ApiOperation("根据id查询模块")
    public ModuleAddDto queryById(@PathVariable("id") String id){
        return moduleService.queryById(id);
    }
    @PutMapping("/edit")
    @ApiOperation("修改模块")
    public Result editModule(@RequestBody ModuleEditDto moduleEditDto){
        boolean result = moduleService.editModule(moduleEditDto);
        return new Result(result,result?"修改模块成功":"修改模块失败",null);
    }
}
